/**
 * 
 */

/**
 * @author Ashley
 *
 */
public class ModOp extends ArithmeticOp
{
	public ModOp() {
		super("%");
	}
	
	@Override
	public boolean isModOp() { 
		return true; 
	}
	
	@Override
	public STO checkOperands(STO left, STO right) {
		if (left.isError()) { 
			return left ;
		}
		if (right.isError()){
			return right ;
		}
		STO sto = null;
		Type l_type = left.getType();
		Type r_type = right.getType();
		boolean l_int = l_type.isInt();
		boolean r_int = r_type.isInt();

		if(l_int && r_int) {
			if(left.isConst() && right.isConst()) {
				sto = new ConstSTO("Mod result", new IntType());
			}
			else {
				if(!left.isConst()) {
					sto = new ExprSTO(left.getName(), new IntType());
				}
				else {
					sto = new ExprSTO(right.getName(), new IntType());
				}
			}
		}
		else {
		 	sto = new ErrorSTO("error1w_Expr");
		}
		return sto;
	}
	
	@Override
	public STO calculate(ConstSTO left, ConstSTO right) {
		STO sto;
		if(right.getFloatValue() == 0.0) {
			sto = new ErrorSTO("error8_Arithmetic");
		}
		else {
			sto = new ConstSTO((left.getName() + "%" + right.getName()), new IntType(), 
				  Integer.toString(left.getIntValue() % right.getIntValue()));
		}
		return sto;
	}
}
